#!/bin/sh

#
# This script creates a back up of an already existing id.txt and/or
# config.xml so they can be restored if necessary after an update
#

echo "Preflight" >> /tmp/script.log
date >> /tmp/script.log

APPBUNDLENAME="LockDown Browser.app"
IDFILE="id.txt"
CFGFILE="config.xml"

echo "Arg1 = $1" >> /tmp/script.log
echo "Arg2 = $2" >> /tmp/script.log
echo "Arg3 = $3" >> /tmp/script.log
echo "Arg4 = $4" >> /tmp/script.log

echo "Working Directory is : " `pwd` >> /tmp/script.log

if [ -e "$2/$APPBUNDLENAME/$IDFILE" ]
then
	echo "Copying $2/$APPBUNDLENAME/$IDFILE to /tmp/LDBPreviousId.txt" >> /tmp/script.log
	cp "$2/$APPBUNDLENAME/$IDFILE" "/tmp/LDBPreviousId.txt" >> /tmp/script.log
else
	echo "$2/$APPBUNDLENAME/$IDFILE does not exist. Backup cancelled." >> /tmp/script.log
fi

# probably don't need this, since updates will need to have a config.xml for
# branding anyway, but here it is anyway just in case
if [ -e "$2/$APPBUNDLENAME/$CFGFILE" ]
then
	echo "Copying $2/$APPBUNDLENAME/$CFGFILE to /tmp/LDBPreviousConfig.xml" >> /tmp/script.log
	cp "$2/$APPBUNDLENAME/$CFGFILE" "/tmp/LDBPreviousConfig.xml" >> /tmp/script.log
else
	echo "$2/$APPBUNDLENAME/$CFGFILE does not exist. Backup cancelled." >> /tmp/script.log
fi

